package com.cp.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    Logger logger = LoggerFactory.getLogger(IndexController.class);
    @RequestMapping("/index")
    public String index() {
        logger.warn("index....");
        return "/index.html";
    }

    @RequestMapping("/login")
    public String login(){
        logger.error("login...");
        return "/login.html";
    }

    @RequestMapping("/toLogin")
    public String toLogin(@RequestParam(name = "userName") String userName, HttpSession session){
        if ("a".equalsIgnoreCase(userName)) {
            session.setAttribute("user", userName);
            return "redirect:/index";
        } else {
            return "redirect:/login";
        }
    }
}
